import os
import tkinter as tk
from tkinter import ttk

window = tk.Tk()
# 创建一个Treeview小部件
tree = ttk.Treeview(window, columns=("Type", "Size"))

# 设置样式
tree["show"] = "headings"
tree["height"] =10

# 设置事件处理
def on_double_click(event):
    item = tree.selection()[0]
    file_path = tree.item(item)["text"]
    file_type = tree.item(item)["values"][0]
    file_size = tree.item(item)["values"][1]
    print(f"You double clicked on {file_path} ({file_type}) - Size: {file_size} bytes")

tree.bind("<Double-1>", on_double_click)

# 添加内容
path = "E:/"
for file in os.listdir(path):
    file_path = os.path.join(path, file)
    file_type = "File" if os.path.isfile(file_path) else "Directory"
    file_size = os.path.getsize(file_path)
    tree.insert("", "end", text=file, values=(file_type, file_size))

tree.pack()

# 运行窗口的主循环
window.mainloop()
